<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
    <title>修改排课</title>
    <link rel="stylesheet" type="text/css" href="Assets/css/reset.css"/>
    <script type="text/javascript" src="Assets/js/jquery-1.8.3.min.js"></script>
    <link rel="stylesheet" type="text/css" href="Assets/plugins/FlexSlider/flexslider.css">
    <script type="text/javascript" src="Assets/plugins/FlexSlider/jquery.flexslider.js"></script>
    <script type="text/javascript" src="Assets/js/main.js"></script>
    <link rel="stylesheet" type="text/css" href="Assets/css/thems.css">
    <link rel="stylesheet" type="text/css" href="Assets/css/responsive.css">
    <!-- -------------------------------------------------- -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

    <script language="javascript">

    </script>
</head>

<body>
<!--头部-->
<div class="head clearfix">
    <div class="logo"><a href=""><img src="Assets/images/logo.jpg" alt="信本财富"/></a></div>
    <div class="head_r">
        <div class="lang">
            <a href="">中文</a>|
        </div>
        <ul class="nav clearfix">
            <li class="now"><a href="index.html">首页</a></li>
            <li><a href="product.html">课程管理</a></li>
            <li><a href="vip.html">会员管理</a></li>
            <li><a href="sig_in.html">签到管理</a></li>
            <li><a href="custom-made.html">定制会员卡</a></li>
            <li><a href="subbranch.html">场馆管理</a></li>
            <li><a href="staff.html">员工管理</a></li>
        </ul>
        <div class="nav_m">
            <span class="n_icon">&nbsp;</span>
            <ul>
                <li><a href="index.html">首页</a></li>
                <li><a href="about.html">关于信本</a></li>
                <li><a href="news.html">信本动态</a></li>
                <li class="now"><a href="product.html">信本业务</a></li>
                <li><a href="#">信本学院</a></li>
                <li><a href="#">社会责任</a></li>
                <li><a href="#">联系我们</a></li>
            </ul>
        </div>
    </div>
</div>
<!--头部-->
<!--幻灯片-->
<div class="banner">
    <div class="slider">
        <div class="flexslider">
            <ul class="slides">
                <li>
                    <a href=""><img src="Assets/upload/banner.jpg" alt="" /></a>
                </li>
                <li>
                    <a href=""><img src="Assets/upload/banner_a.jpg" alt="" /></a>
                </li>
                <li>
                    <a href=""><img src="Assets/upload/banner_b.jpg" alt="" /></a>
                </li>
                <li>
                    <a href=""><img src="Assets/upload/banner_c.jpg" alt="" /></a>
                </li>
                <li>
                    <a href=""><img src="Assets/upload/banner_d.jpg" alt="" /></a>
                </li>
            </ul>
        </div>
    </div>
</div>
<!--幻灯片-->
<div class="scd clearfix">
    <div class="scd_l">
        <div class="title"><span>增加课程</span></div>
        <ul class="s_nav">
            <li><a onclick="Pkadd()"><em>确定提交</em></a></li>
            <li><a href="paike.html"><em>返回</em></a></li>
        </ul>
    </div>
    <div class="scd_r">
        <div class="s_title">

            <div class="pst">
                当前位置：
                <a href="">首页</a>>
                <a href="">课程管理</a>>
                <a href="">排课</a>>
            </div>
        </div>

        <div class="scd_m">
            <div class="pro_d">

                <div class="form-group">
                    <label for="name">课程名称</label>
                    <select name="" id="courses">
                        <option selected="selected"  value="00">--请选择-- </option>
                    </select>
                </div>

                <div class="form-group" id="coursesintro">
                    <label for="name">课程名称</label><br>
                    <label for="name">课程类型</label><br>
                    <label for="name">课程难度</label><br>
                    <label for="name">课程简介</label><br>
                    <label for="name">课程图片</label><br>
                </div>

                <div class="form-group">
                    <label for="name">教练</label>
                    <select name="" id="staff">

                    </select>
                </div>

                <div class="form-group">
                    <label for="name">价格</label>
                    <input type="text" class="form-control" id="name"
                           placeholder="请输入价格">
                </div>

                <div class="form-group">
                    <label for="name">场馆</label>
                    <select name="" id="shopid">
                        <option selected="selected" >--请选择-- </option>
                    </select>
                    <label for="name">教室</label>
                    <select name="" id="classroom">
                        <option selected="selected" id="xu" value="00">--请选择-- </option>

                    </select>
                    教室容纳人数:<b id="classroomRR"></b>

                </div>


                <br>
                <br>
                <br>
                <button type="submit" class="btn btn-default" onclick="Pkadd()">添加</button>

            </div>
        </div>
    </div>
</div>

</body>
</html>
<script>

    // <!--课程list-->
    var arrCourses  = new Array();
    //教室list
    var arr1  = new Array();

    var arrTime = new Array();
    $(function () {
        var path = "/" + location.pathname.split("/")[1];
        $.get(path+"/queryClassroom",function (list) {
            arr1 = list;
            console.log(list+"=================")
            var shopid;
            $.each(list,function (i,li) {
                if (li.shop.shopid==null){
                    console.log("===============")
                }else {
                    shopid = li.shop.shopid;
                    $("#shopid").append(
                        '<option value='+li.shop.shopid+ '>'+li.shop.shopname+'</option>'
                    )
                }
                console.log(li)

                var path = "/" + location.pathname.split("/")[1];
                $("#classroom").append(
                    '<option name='+shopid+' id='+li.classroomId+' class ='+shopid +' value='+li.classroomId+'>教室名称:'+li.classroomName+'</option>'

                );

            });
            $("#classroom option").hide();
        },"json");

        //向教师栏动态插入
        var path = "/" + location.pathname.split("/")[1];
        $.get(path+"/queryStaffPK",function (list) {

            $.each(list,function (i,li) {

                $("#staff").append(
                    '<option id='+li.staffid+' name='+li.staffsupport+' value='+li.staffid+ '>'+li.staffname+'</option>'
                )
            });


        },"json");


        //向课程栏动态插入
        var path = "/" + location.pathname.split("/")[1];
        $.get(path+"/queryCoursesPK",function (list) {
            arrCourses = list;
            $.each(list,function (i,li) {

                $("#courses").append(
                    '<option  value='+li.coursesid+ ' >'+li.coursesname+'</option>'
                )
            });


        },"json");

        var thisURL = document.URL;
        var getval = null;
        //判断是不是带有id的请求
        var dates;
        var times;
        if (thisURL.search("times=") != -1) {
            getval = thisURL.split('?')[1];
            console.log(getval);
            var  datesss = getval.split("&")[0];
            var  timesss = getval.split("&")[1];
            dates = datesss.split("=")[1];
            times = timesss.split("=")[1];
        }
        console.log(dates+"===="+times);


        $.get(path+"/coursePKQueryTime",{"courseDate":dates, "courseTime":times},function (list) {

            arrTime = list;
            // $.each(list,function (i,li) {
            //     var stid =  "#"+li.courseTeacherId;
            //     var classid  = "#" +li.courseClassroomId
            //     $(stid).hide();
            //     $(classid).hide();
            // });


        },"json");





    });

    $("#shopid").change(function () {

        $("#classroom option").hide();
        var vall = $(this).val();
        var vall1=  "."+vall;
        $(vall1).show();
        $.each(arrTime,function (i1,li1) {
            var stid =li1.courseTeacherId;
            var classid  = li1.courseClassroomId
            $("select[id='staff'] option[id="+stid+"]").hide();
            $("select[id='classroom'] option[id="+classid+"]").hide();
        });

    });

    $('#classroom').change(function () {
        $("#classroomRR").empty();
        var  thisval1=  $(this).val();
        $.each(arr1,function (i,li) {

            if (thisval1==li.classroomId){
                $("#classroomRR").append(
                    '<b id="classroomRU">'+li.classroomCapacity+'</b>'
                )

            }

        });


    });


    $('#courses').change(function () {

        // var thisURL = document.URL;
        // var getval = null;
        // //判断是不是带有id的请求
        // var dates;
        // var times;
        // if (thisURL.search("times=") != -1) {
        //     getval = thisURL.split('?')[1];
        //     console.log(getval);
        //     var  datesss = getval.split("&")[0];
        //     var  timesss = getval.split("&")[1];
        //     dates = datesss.split("=")[1];
        //     times = timesss.split("=")[1];
        // }
        // console.log(dates+"===="+times);
        // // 查询排课表把时间段占用的 教师   教室  option进行删除
        // var path = "/" + location.pathname.split("/")[1];
        // $.get(path+"/coursePKQueryTime",{"courseDate":dates, "courseTime":times},function (list) {
        //     $.each(list,function (i,li) {
        //         var stid =  "#"+li.courseTeacherId;
        //         var classid  = "#" +li.courseClassroomId
        //         $(stid).hide();
        //         $(classid).hide();
        //     });
        //
        //
        // },"json");



        $("#coursesintro").empty();
        var  thisval=  $(this).val();
        console.log(  +"课程val值");
        $.each(arrCourses,function (i,li) {





            if (thisval==li.coursesid) {
                var path = "/" + location.pathname.split("/")[1];
                var paths= path+"/"+li.coursesimg;

                $("#coursesintro").append(
                    '<label for="name">课程名称:</label><b id="names">'+li.coursesname+'</b><br>'+
                    '<label for="name">课程类型:</label><b id="types">'+li.coursestype+'</b><br>'+
                    '<label for="name">课程难度:</label><b id="grades">'+li.coursesgrade+'</b>星<br>'+
                    '<label for="name">课程简介:</label><p id="intros">'+li.coursesintro+'</p>'+
                    '<label for="name">课程图片:</label><img id="imgs" width="400px" height="400px" src='+paths+'><br>'
                );


                if (li.coursestype=="团课"){
                    $("select[id='staff'] option[name='不支持']").show();
                    $("select[id='staff'] option[name='支持']").hide();
                    $.each(arrTime,function (i,li) {
                        var stid =li.courseTeacherId;
                        var classid  = li.courseClassroomId
                        $("select[id='staff'] option[id="+stid+"]").hide();
                        $("select[id='classroom'] option[id="+classid+"]").hide();
                    });

                }
                if (li.coursestype=="私教"){
                    $("select[id='staff'] option[name='支持']").show();
                    $("select[id='staff'] option[name='不支持']").hide();
                    $.each(arrTime,function (i,li) {
                        var stid1 =li.courseTeacherId;
                        var classid  = li.courseClassroomId
                        $("select[id='staff'] option[id="+stid1+"]").hide();
                        $("select[id='classroom'] option[id="+classid+"]").hide();
                    });
                }

            }
            console.log(li.coursesname+"===名称== ");
        });

    });

    // function QueryTime() {
    //     var thisURL = document.URL;
    //     var getval = null;
    //     //判断是不是带有id的请求
    //     var dates;
    //     var times;
    //     if (thisURL.search("times=") != -1) {
    //         getval = thisURL.split('?')[1];
    //         console.log(getval);
    //         var  datesss = getval.split("&")[0];
    //         var  timesss = getval.split("&")[1];
    //         dates = datesss.split("=")[1];
    //         times = timesss.split("=")[1];
    //     }
    //     console.log(dates+"===="+times);
    //     // 查询排课表把时间段占用的 教师   教室  option进行删除
    //     var path = "/" + location.pathname.split("/")[1];
    //     $.get(path+"/coursePKQueryTime",{"courseDate":dates, "courseTime":times},function (list) {
    //         $.each(list,function (i,li) {
    //             var stid =  "#"+li.courseTeacherId;
    //             var classid  = "#" +li.courseClassroomId
    //             $(stid).hide();
    //             $(classid).hide();
    //         });
    //
    //
    //     },"json");
    // }


    function Pkadd() {
        var shopText = $("#shopid").find("option:selected").text();
        var shopTextid = $("#shopid").val();
        var classroomText = $("#classroom").find("option:selected").text();
        var classroomTextid = $("#classroom").val();
        var staffText = $("#staff").find("option:selected").text();
        var staffTextid = $("#staff").val();
        var coursesText = $("#courses").find("option:selected").text();
        var coursesTextid = $("#courses").val();

        var names= $("#names").text();
        var types=  $("#types").text();
        var grades= $("#grades").text();
        var intros= $("#intros").text();
        var imgs= $("#imgs").attr('src');
        var price= $("#name").val();
        var classroomRU= $("#classroomRU").text();
        console.log(classroomRU+"==人数=")
        console.log(shopText+"==下拉框文本值=="+classroomText+"=教室="+staffText+"==教师=="+coursesText+"==课程==")

        var thisURL = document.URL;
        var getval = null;
        //判断是不是带有id的请求
        var dates;
        var times;
        if (thisURL.search("times=") != -1) {
            getval = thisURL.split('?')[1];
            console.log(getval);
            var  datesss = getval.split("&")[0];
            var  timesss = getval.split("&")[1];
            dates = datesss.split("=")[1];
            times = timesss.split("=")[1];
        }
        console.log(dates+"===="+times);




        //添加排课表
        var path = "/" + location.pathname.split("/")[1];
        $.post(path+"/CourseAddPK",
            {"courseNameId":coursesTextid,"courseName":coursesText,
                "courseClubid":shopTextid,"courseClubName":shopText,
                "courseClassroomId":classroomTextid,"courseClassroom":classroomText,
                "courseTeacherId":staffTextid,"courseTeacher":staffText,
                "courseCatagory":types,"courseDifficulty":grades,
                "courseIntroduce":intros,"courseImg":imgs,
                "coursePrice":price,"courseDate":dates,
                "courseTime":times,"courseNum":classroomRU,
                "courseRemainNum":classroomRU
            },function (list) {

                var li= eval(list);
                console.log(li+"===============");
                if (li){

                    window.location.href="paike.html"

                } else {
                    alert("上传信息失败")

                }

            },"json");


    }
</script>
